package com.huawei.eihealth.demo;

import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ClientRequestException;
import com.huaweicloud.sdk.core.exception.ServerResponseException;
import com.huaweicloud.sdk.eihealth.v1.EiHealthClient;
import com.huaweicloud.sdk.eihealth.v1.model.CreateWorkflowRequest;
import com.huaweicloud.sdk.eihealth.v1.model.WorkflowDto;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;

public class CreateWorkflowDemo {
    private static final Logger LOGGER = LoggerFactory.getLogger(CreateWorkflowDemo.class);

    public static void main(String[] args) {

        // 设置AK和SK
        String ak = "<YOUR AK>";
        String sk = "<YOUR SK>";

        // projectId 云服务所在项目 ID
        String projectId = "<YOUR PROJECT_ID>";

        // endpoint 华为云各服务应用区域和各服务的终端节点
        String endpoint = "<YOUR ENDPOINT>";

        // 初始化客户端
        BasicCredentials auth = new BasicCredentials().withAk(ak).withSk(sk).withProjectId(projectId);
        EiHealthClient eiHealthClient = EiHealthClient.newBuilder().withCredential(auth).withEndpoint(endpoint).build();

        CreateWorkflowRequest workflowRequest = new CreateWorkflowRequest();

        // 设置医疗智能体的项目id
        workflowRequest.setEihealthProjectId("your eihealth_project_id");

        // 初始化workflow请求体
        WorkflowDto workflowDto = initWorkflowDto();
        workflowRequest.setBody(workflowDto);

        try {
            eiHealthClient.createWorkflow(workflowRequest);
        } catch (ClientRequestException | ServerResponseException e) {
            LOGGER.error(String.valueOf(e.getHttpStatusCode()));
            LOGGER.error(e.getErrorCode());
            LOGGER.error(e.getMessage());
        }
    }

    private static WorkflowDto initWorkflowDto() {
        WorkflowDto workflowDto = new WorkflowDto();
        workflowDto.setName("workflow-demo");
        workflowDto.setVersion("1.0");
        workflowDto.setTasks(new ArrayList<>());
        return workflowDto;
    }
}
